package com.company.gxcpc2018;

import java.awt.Point;
import java.util.Scanner;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Gxcpc7 {

    private static int[] bank;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt(), k = sc.nextInt();
            Point[] list = Stream.generate(() -> {
                Point point = new Point();
                point.setLocation(sc.nextInt(), sc.nextInt());
                return point;
            }).limit(n).toArray(Point[]::new);
            bank = IntStream.range(0, n).toArray();
            for (int i = 0; i < n - 1; i++) {
                for (int j = i + 1; j < n; j++) {
                    Point left = list[i];
                    Point right = list[j];
                    if (Math.abs(left.x - right.x) <= k || Math.abs(left.y - right.y) <= k) {
                        bank[j] = bank[i];
                    }
                }
            }
            for (int j : bank) {
                findSet(j);
            }
            long count = IntStream.of(bank).distinct().count();
            System.out.println(count);
        }
    }

    public static int findSet(int index) {
        if (index == bank[index]) {
            return bank[index];
        }
        return bank[index] = findSet(bank[index]);
    }
}
